{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "44b33e80",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<module 'spatial_autocorr' from '../GTWR_ana\\\\spatial_autocorr.py'>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import geopandas as gpd\n",
    "from coord_convert.transform import wgs2gcj, wgs2bd, gcj2wgs, gcj2bd, bd2wgs, bd2gcj\n",
    "import matplotlib.pyplot as plt\n",
    "import os\n",
    "import transbigdata as tbd\n",
    "import sys\n",
    "sys.path.append(\"../GTWR_ana/\")\n",
    "from datetime import datetime, timezone, timedelta\n",
    "from matplotlib import ticker\n",
    "import DataMerge\n",
    "import DataClearn\n",
    "import regre_gtwr\n",
    "import data_st_vis\n",
    "import data_norn\n",
    "import spatial_autocorr\n",
    "import copy\n",
    "import time, datetime\n",
    "import importlib\n",
    "importlib.reload(DataMerge)\n",
    "importlib.reload(DataClearn)\n",
    "importlib.reload(regre_gtwr)\n",
    "importlib.reload(data_st_vis)\n",
    "importlib.reload(data_norn)\n",
    "importlib.reload(spatial_autocorr)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c01fa9db",
   "metadata": {},
   "source": [
    "# 1.Integration of independent and dependent variables\n",
    "## 1.1 Aggregation of Dependent and independent variables"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d5c5dd97",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Compilation of datasets with casualties\n",
    "x_file_list = [\"../../data/各时间片各栅格交通状态数据/avg_traffic_freq.csv\"]\n",
    "DataMerge.data_agg.merge(y_file=\"../../data/各时间片各栅格事故频率数据/inj_freq_ts_data.csv\",\n",
    "               x_file_list=x_file_list,\n",
    "               grid_data_file=\"../../data/ResearchAreaGrid/grid/research_grid.shp\",\n",
    "               merge_data_save_file=\"../../data/merge_data/inj_data/inj_merge_data.shp\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "1a6ce03c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Compilation of Datasets for Property Damage Only\n",
    "x_file_list = [\"../../data/各时间片各栅格交通状态数据/avg_traffic_freq.csv\"]\n",
    "DataMerge.data_agg.merge(y_file=\"../../data/各时间片各栅格事故频率数据/pdo_freq_ts_data.csv\",\n",
    "               x_file_list=x_file_list,\n",
    "               grid_data_file=\"../../data/ResearchAreaGrid/grid/research_grid.shp\",\n",
    "               merge_data_save_file=\"../../data/merge_data/pdo_data/pdo_merge_data.shp\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "89179ee3",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "../GTWR_ana\\DataMerge.py:55: UserWarning: Column names longer than 10 characters will be truncated when saved to ESRI Shapefile.\n",
      "  df.to_file(merge_data_save_file)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>LONCOL</th>\n",
       "      <th>LATCOL</th>\n",
       "      <th>ts</th>\n",
       "      <th>acci_freq</th>\n",
       "      <th>avg_freq</th>\n",
       "      <th>in_degree</th>\n",
       "      <th>out_degree</th>\n",
       "      <th>node_betwe</th>\n",
       "      <th>pagerank</th>\n",
       "      <th>street_den</th>\n",
       "      <th>intersecti</th>\n",
       "      <th>circuity_a</th>\n",
       "      <th>edge_densi</th>\n",
       "      <th>orientatio</th>\n",
       "      <th>bike_stree</th>\n",
       "      <th>cr1</th>\n",
       "      <th>cr2</th>\n",
       "      <th>cr3</th>\n",
       "      <th>cr4</th>\n",
       "      <th>cr5</th>\n",
       "      <th>cr6</th>\n",
       "      <th>normalized</th>\n",
       "      <th>geometry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.389523</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.610477</td>\n",
       "      <td>0.386853</td>\n",
       "      <td>POLYGON ((120.22035 30.13370, 120.22035 30.14269, 120.23076 30.14269, 120.23076 30.13370, 120.22035 30.13370))</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   LONCOL  LATCOL  ts  acci_freq  avg_freq  in_degree  out_degree  node_betwe  pagerank  street_den  intersecti  circuity_a  edge_densi  orientatio  bike_stree  cr1  cr2  cr3       cr4  cr5       cr6  normalized                                                                                                        geometry\n",
       "0       0       0   0        0.0       0.0        0.0         0.0         0.0       0.0         0.0         0.0         0.0         0.0         0.0         0.0  0.0  0.0  0.0  0.389523  0.0  0.610477    0.386853  POLYGON ((120.22035 30.13370, 120.22035 30.14269, 120.23076 30.14269, 120.23076 30.13370, 120.22035 30.13370))"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Organize the dataset with casualties and generate the final file\n",
    "x_file_list = [\"../../code/OSM道路设施/osm数据道路设施情况.csv\",\"../../code/POI建成环境/建成环境.csv\"]\n",
    "DataMerge.data_agg.merge_staic_variable(x_file_list=x_file_list,\n",
    "                   grid_data_file=\"../../data/merge_data/inj_data/inj_merge_data.shp\",\n",
    "                   merge_data_save_file=\"../../data/merge_data/inj_data_all/inj_merge_data.shp\")\n",
    "df = gpd.read_file(\"../../data/merge_data/inj_data_all/inj_merge_data.shp\")\n",
    "df.head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "e66a1f72",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "../GTWR_ana\\DataMerge.py:55: UserWarning: Column names longer than 10 characters will be truncated when saved to ESRI Shapefile.\n",
      "  df.to_file(merge_data_save_file)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>LONCOL</th>\n",
       "      <th>LATCOL</th>\n",
       "      <th>ts</th>\n",
       "      <th>acci_freq</th>\n",
       "      <th>avg_freq</th>\n",
       "      <th>in_degree</th>\n",
       "      <th>out_degree</th>\n",
       "      <th>node_betwe</th>\n",
       "      <th>pagerank</th>\n",
       "      <th>street_den</th>\n",
       "      <th>intersecti</th>\n",
       "      <th>circuity_a</th>\n",
       "      <th>edge_densi</th>\n",
       "      <th>orientatio</th>\n",
       "      <th>bike_stree</th>\n",
       "      <th>cr1</th>\n",
       "      <th>cr2</th>\n",
       "      <th>cr3</th>\n",
       "      <th>cr4</th>\n",
       "      <th>cr5</th>\n",
       "      <th>cr6</th>\n",
       "      <th>normalized</th>\n",
       "      <th>geometry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.389523</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.610477</td>\n",
       "      <td>0.386853</td>\n",
       "      <td>POLYGON ((120.22035 30.13370, 120.22035 30.14269, 120.23076 30.14269, 120.23076 30.13370, 120.22035 30.13370))</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   LONCOL  LATCOL  ts  acci_freq  avg_freq  in_degree  out_degree  node_betwe  pagerank  street_den  intersecti  circuity_a  edge_densi  orientatio  bike_stree  cr1  cr2  cr3       cr4  cr5       cr6  normalized                                                                                                        geometry\n",
       "0       0       0   0        0.0       0.0        0.0         0.0         0.0       0.0         0.0         0.0         0.0         0.0         0.0         0.0  0.0  0.0  0.0  0.389523  0.0  0.610477    0.386853  POLYGON ((120.22035 30.13370, 120.22035 30.14269, 120.23076 30.14269, 120.23076 30.13370, 120.22035 30.13370))"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Compile the dataset for property damage only and generate the final file\n",
    "x_file_list = [\"../../code/OSM道路设施/osm数据道路设施情况.csv\",\"../../code/POI建成环境/建成环境.csv\"]\n",
    "DataMerge.data_agg.merge_staic_variable(x_file_list=x_file_list,\n",
    "                   grid_data_file=\"../../data/merge_data/pdo_data/pdo_merge_data.shp\",\n",
    "                   merge_data_save_file=\"../../data/merge_data/pdo_data_all/pdo_merge_data.shp\")\n",
    "df = gpd.read_file(\"../../data/merge_data/pdo_data_all/pdo_merge_data.shp\")\n",
    "df.head(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4d5805f2",
   "metadata": {},
   "source": [
    "## 1.2 Data cleansing and preprocessing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "2f3c1031",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Data restoration for grids with traffic accidents not zero but traffic volume zero (only property damage)\n",
    "DataClearn.clearn.clearn_traffic_state(merge_data=\"../../data/merge_data/pdo_data_all/pdo_merge_data.shp\",\n",
    "                            data_save_file=\"../../data/merge_data/pdo_data_clearn/pdo_merge_data.shp\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "a24a0657",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Data repair for grids with traffic accidents not zero but traffic volume zero (with casualties)\n",
    "DataClearn.clearn.clearn_traffic_state(merge_data=\"../../data/merge_data/inj_data_all/inj_merge_data.shp\",\n",
    "                            data_save_file=\"../../data/merge_data/inj_data_clearn/inj_merge_data.shp\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "d2544300",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Renaming only property loss data\n",
    "DataClearn.clearn.field_rename(merge_data=\"../../data/merge_data/pdo_data_clearn/pdo_merge_data.shp\",\n",
    "                        data_save_file=\"../../data/merge_data/pdo_data_rename/pdo_merge_data.shp\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "da95f068",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Renaming of personnel injury data exists\n",
    "DataClearn.clearn.field_rename(merge_data=\"../../data/merge_data/inj_data_clearn/inj_merge_data.shp\",\n",
    "                        data_save_file=\"../../data/merge_data/inj_data_rename/inj_merge_data.shp\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "dc800210",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Shrinking processing of property loss data only\n",
    "DataClearn.clearn.winsor_data(merge_data=\"../../data/merge_data/pdo_data_rename/pdo_merge_data.shp\" ,\n",
    "                       explain_var_list=['x1','x2','x3','x4','x5','x6','x7','x8','x9','x10','x11','x12',\n",
    "                                         'x13','x14','x15','x16','x17','x18'] ,\n",
    "                       data_save_file=\"../../data/merge_data/pdo_data_rename/pdo_merge_data.shp\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "5051800c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Shrinking processing of personnel injury data\n",
    "DataClearn.clearn.winsor_data(merge_data=\"../../data/merge_data/inj_data_rename/inj_merge_data.shp\" ,\n",
    "                       explain_var_list=['x1','x2','x3','x4','x5','x6','x7','x8','x9','x10','x11','x12',\n",
    "                                         'x13','x14','x15','x16','x17','x18'] ,\n",
    "                       data_save_file=\"../../data/merge_data/inj_data_rename/inj_merge_data.shp\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "ef59b761",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Standardize only property loss data\n",
    "data_norn.norm.start(data_file=\"../../data/merge_data/pdo_data_rename/pdo_merge_data.shp\",\n",
    "               output_file=\"../../data/merge_data/pdo_data_norm/pdo_merge_data.shp\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "e5141548",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Standardization of casualties data\n",
    "data_norn.norm.start(data_file=\"../../data/merge_data/inj_data_rename/inj_merge_data.shp\",\n",
    "               output_file=\"../../data/merge_data/inj_data_norm/inj_merge_data.shp\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3422720a",
   "metadata": {},
   "source": [
    "# 2.Fitting\n",
    "## 2.1 Collinearity judgment and spatial autocorrelation judgment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "48d00be2",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "const     1.000000\n",
      "x1        1.174995\n",
      "x2       40.114016\n",
      "x3       37.398221\n",
      "x4        1.403615\n",
      "x5        1.599282\n",
      "x6       56.516765\n",
      "x7        4.971021\n",
      "x8        1.394214\n",
      "x9       29.807749\n",
      "x10       2.407424\n",
      "x11      34.566168\n",
      "x12       3.679095\n",
      "x13       2.212647\n",
      "x14       2.003127\n",
      "x15       1.790075\n",
      "x16       2.017787\n",
      "x17       2.336235\n",
      "x18       4.791538\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "# 共线性判断\n",
    "regre_gtwr.regression.cal_VIF(data_file=\"../../data/merge_data/pdo_data_norm/pdo_merge_data.shp\",\n",
    "                       explain_var_list=['x1','x2','x3','x4','x5','x6','x7','x8','x9','x10','x11','x12',\n",
    "                                         'x13','x14','x15','x16','x17','x18'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "160f5213",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "const     1.000000\n",
      "x1        1.271896\n",
      "x2       40.493604\n",
      "x3       37.674204\n",
      "x4        1.406573\n",
      "x5        1.619934\n",
      "x6       56.454735\n",
      "x7        4.980235\n",
      "x8        1.395671\n",
      "x9       29.779962\n",
      "x10       2.407791\n",
      "x11      34.550355\n",
      "x12       3.669176\n",
      "x13       2.210987\n",
      "x14       2.018226\n",
      "x15       1.785456\n",
      "x16       1.992803\n",
      "x17       2.316060\n",
      "x18       4.802528\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "# 共线性判断\n",
    "regre_gtwr.regression.cal_VIF(data_file=\"../../data/merge_data/inj_data_norm/inj_merge_data.shp\",\n",
    "                       explain_var_list=['x1','x2','x3','x4','x5','x6','x7','x8','x9','x10','x11','x12',\n",
    "                                         'x13','x14','x15','x16','x17','x18'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b9f64efe",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正在检验的变量为: x1\n",
      "Moran's I 值为： 0.1314503491911806\n",
      "随机分布假设下Z检验值为： 60.5880296442641\n",
      "随机分布假设下Z检验的P值为： 0.0\n",
      "正态分布假设下Z检验值为： 60.59944487854433\n",
      "正态分布假设下Z检验的P值为： 0.0\n",
      "正在检验的变量为: x4\n",
      "Moran's I 值为： 0.1807774971258599\n",
      "随机分布假设下Z检验值为： 83.23644381179672\n",
      "随机分布假设下Z检验的P值为： 0.0\n",
      "正态分布假设下Z检验值为： 83.26060218810345\n",
      "正态分布假设下Z检验的P值为： 0.0\n",
      "正在检验的变量为: x5\n",
      "Moran's I 值为： 0.07540903399366293\n",
      "随机分布假设下Z检验值为： 34.84710392112268\n",
      "随机分布假设下Z检验的P值为： 0.0\n",
      "正态分布假设下Z检验值为： 34.85376298330766\n",
      "正态分布假设下Z检验的P值为： 0.0\n",
      "正在检验的变量为: x7\n",
      "Moran's I 值为： 0.2710668642060623\n",
      "随机分布假设下Z检验值为： 124.70758555489827\n",
      "随机分布假设下Z检验的P值为： 0.0\n",
      "正态分布假设下Z检验值为： 124.7400234896241\n",
      "正态分布假设下Z检验的P值为： 0.0\n",
      "正在检验的变量为: x8\n",
      "Moran's I 值为： 0.23057100353419108\n",
      "随机分布假设下Z检验值为： 106.11338212052183\n",
      "随机分布假设下Z检验的P值为： 0.0\n",
      "正态分布假设下Z检验值为： 106.13600709105813\n",
      "正态分布假设下Z检验的P值为： 0.0\n",
      "正在检验的变量为: x10\n",
      "Moran's I 值为： 0.28093594388963683\n",
      "随机分布假设下Z检验值为： 129.24210442632375\n",
      "随机分布假设下Z检验的P值为： 0.0\n",
      "正态分布假设下Z检验值为： 129.27393182558168\n",
      "正态分布假设下Z检验的P值为： 0.0\n",
      "正在检验的变量为: x12\n",
      "Moran's I 值为： 0.18834545294571786\n",
      "随机分布假设下Z检验值为： 86.71627272869205\n",
      "随机分布假设下Z检验的P值为： 0.0\n",
      "正态分布假设下Z检验值为： 86.7373618331715\n",
      "正态分布假设下Z检验的P值为： 0.0\n",
      "正在检验的变量为: x13\n",
      "Moran's I 值为： 0.3189988313547504\n",
      "随机分布假设下Z检验值为： 146.73289153915667\n",
      "随机分布假设下Z检验的P值为： 0.0\n",
      "正态分布假设下Z检验值为： 146.76022723526566\n",
      "正态分布假设下Z检验的P值为： 0.0\n",
      "正在检验的变量为: x14\n",
      "Moran's I 值为： 0.2751723940000486\n",
      "随机分布假设下Z检验值为： 126.5999336871177\n",
      "随机分布假设下Z检验的P值为： 0.0\n",
      "正态分布假设下Z检验值为： 126.62612597874038\n",
      "正态分布假设下Z检验的P值为： 0.0\n",
      "正在检验的变量为: x15\n",
      "Moran's I 值为： 0.23343655986836503\n",
      "随机分布假设下Z检验值为： 107.42518922458538\n",
      "随机分布假设下Z检验的P值为： 0.0\n",
      "正态分布假设下Z检验值为： 107.45245909744843\n",
      "正态分布假设下Z检验的P值为： 0.0\n",
      "正在检验的变量为: x16\n",
      "Moran's I 值为： 0.31012305202184576\n",
      "随机分布假设下Z检验值为： 142.66472438589503\n",
      "随机分布假设下Z检验的P值为： 0.0\n",
      "正态分布假设下Z检验值为： 142.682646427751\n",
      "正态分布假设下Z检验的P值为： 0.0\n",
      "正在检验的变量为: x17\n",
      "Moran's I 值为： 0.17118400444147452\n",
      "随机分布假设下Z检验值为： 78.83589490301144\n",
      "随机分布假设下Z检验的P值为： 0.0\n",
      "正态分布假设下Z检验值为： 78.85330000317175\n",
      "正态分布假设下Z检验的P值为： 0.0\n",
      "正在检验的变量为: x18\n",
      "Moran's I 值为： 0.22875332754167332\n",
      "随机分布假设下Z检验值为： 105.2898228303015\n",
      "随机分布假设下Z检验的P值为： 0.0\n",
      "正态分布假设下Z检验值为： 105.30095695479645\n",
      "正态分布假设下Z检验的P值为： 0.0\n"
     ]
    }
   ],
   "source": [
    "# 空间自相关性判断\n",
    "for tmp_var in ['x1','x4','x5','x7','x8','x10','x12','x13','x14','x15','x16','x17','x18']:\n",
    "    spatial_autocorr.autocorr.start(data_file=\"../../data/merge_data/pdo_data_norm/pdo_merge_data.shp\",\n",
    "                   test_var=tmp_var)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8595e4a9",
   "metadata": {},
   "source": [
    "## 2.2 GTWR"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "0d6a11da",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bw:  5.1 , tau:  9.7 , score:  4793.812630895792\n",
      "bw:  3.2 , tau:  3.0 , score:  4663.579861865374\n",
      "bw:  1.9 , tau:  0.6 , score:  4483.5440590395265\n",
      "bw:  1.2 , tau:  0.1 , score:  4317.859459670564\n",
      "bw:  1.2 , tau:  0.1 , score:  4317.859459670564\n",
      "bw:  1.2 , tau:  0.1 , score:  4317.859459670564\n",
      "bw:  1.0 , tau:  0.1 , score:  4273.10013420979\n",
      "bw:  0.9 , tau:  0.1 , score:  4269.090130007157\n",
      "bw:  0.9 , tau:  0.1 , score:  4269.090130007157\n",
      "bw:  0.9 , tau:  0.1 , score:  4269.090130007157\n",
      "time cost: 0:03:4.091\n",
      "Spatiotemporal Weighted Regression (GTWR) Results\n",
      "---------------------------------------------------------------------------\n",
      "Spatial kernel:                                          Fixed gaussian\n",
      "Model tau used:                                                       0.100\n",
      "Spatial Bandwidth used:                                               0.900\n",
      "Temporal Bandwidth used:                                              2.846\n",
      "\n",
      "Diagnostic information\n",
      "---------------------------------------------------------------------------\n",
      "Residual sum of squares:                                            614.066\n",
      "Effective number of parameters (trace(S)):                          352.185\n",
      "Degree of freedom (n - trace(S)):                                  1831.815\n",
      "Sigma estimate:                                                       0.579\n",
      "Log-likelihood:                                                   -1713.420\n",
      "AIC:                                                               4133.209\n",
      "AICc:                                                              4269.090\n",
      "BIC:                                                               3542.173\n",
      "R2:                                                                   0.719\n",
      "Adj. alpha (95%):                                                     0.002\n",
      "Adj. critical t value (95%):                                          3.096\n",
      "\n",
      "Summary Statistics For GTWR Parameter Estimates\n",
      "---------------------------------------------------------------------------\n",
      "Variable                   Mean        STD        Min     Median        Max\n",
      "-------------------- ---------- ---------- ---------- ---------- ----------\n",
      "X0                        0.019      0.602     -3.644     -0.091      2.158\n",
      "X1                        0.568      0.253     -0.028      0.554      1.469\n",
      "X2                        0.077      0.268     -0.530      0.027      1.793\n",
      "X3                        0.059      0.339     -1.507      0.025      1.326\n",
      "X4                       -0.110      0.364     -2.128     -0.034      0.879\n",
      "X5                        0.184      0.221     -0.642      0.137      1.078\n",
      "X6                        0.073      0.327     -1.019      0.005      1.426\n",
      "X7                       -0.197      0.760     -3.298     -0.141      4.740\n",
      "X8                       -0.044      0.481     -1.854     -0.064      2.277\n",
      "X9                        0.045      0.577     -2.533     -0.014      2.869\n",
      "X10                       0.152      0.450     -1.709      0.108      1.923\n",
      "X11                       0.122      0.569     -2.168      0.044      3.744\n",
      "X12                      -0.081      0.575     -2.477     -0.043      4.072\n",
      "X13                       0.048      0.767     -3.272      0.019      4.268\n",
      "===========================================================================\n",
      "\n",
      "   LONCOL  LATCOL  ts        y        x1        x2        x3        x4        x5        x6       x7      x8        x9       x10      x11       x12       x13      x14      x15       x16       x17       x18                                                                                                        geometry  const_betas  x1_betas  x4_betas  x5_betas  x7_betas  x8_betas  x10_betas  x12_betas  x13_betas  x14_betas  x15_betas  x16_betas  x17_betas  x18_betas\n",
      "0       0       0   0 -0.77623 -1.122329 -1.650384 -1.729306 -1.272613 -1.713273 -1.324008 -1.43865 -1.2494 -1.310982 -1.711913 -1.33971 -1.546237 -1.089479 -1.52412  1.63711 -1.401373  1.501314 -1.991453  POLYGON ((120.22035 30.13370, 120.22035 30.14269, 120.23076 30.14269, 120.23076 30.13370, 120.22035 30.13370))    -0.662446  0.125168  0.010574 -0.008944  0.025877 -0.017602  -0.013216  -0.014141  -0.053006  -0.017709  -0.014136   0.034630   0.028459   0.030235\n",
      "1       0       0   1 -0.77623 -1.122329 -1.650384 -1.729306 -1.272613 -1.713273 -1.324008 -1.43865 -1.2494 -1.310982 -1.711913 -1.33971 -1.546237 -1.089479 -1.52412  1.63711 -1.401373  1.501314 -1.991453  POLYGON ((120.22035 30.13370, 120.22035 30.14269, 120.23076 30.14269, 120.23076 30.13370, 120.22035 30.13370))    -0.639709  0.127438  0.012697 -0.009807  0.022842 -0.012023  -0.012591  -0.021351  -0.057624  -0.009393  -0.007350   0.023046   0.009556   0.039161\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "../GTWR_ana\\regre_gtwr.py:173: UserWarning: Column names longer than 10 characters will be truncated when saved to ESRI Shapefile.\n",
      "  df.to_file(result_data_save_file)\n"
     ]
    }
   ],
   "source": [
    "## PDO\n",
    "regre_gtwr.regression.gtwr_start(data_file=\"../../data/merge_data/pdo_data_norm/pdo_merge_data.shp\",\n",
    "                          explain_var_list=['x1','x4','x5','x7','x8','x10','x12','x13','x14','x15','x16','x17','x18'],\n",
    "                          result_data_save_file=\"../../data/GTWR_result/pdo_betas/betas.shp\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "52086b63",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bw:  8.3 , tau:  2.7 , score:  5995.095067020855\n",
      "bw:  10.2 , tau:  4.3 , score:  5994.928166752898\n",
      "bw:  11.5 , tau:  5.5 , score:  5994.866533074843\n",
      "bw:  12.2 , tau:  6.3 , score:  5994.843735904936\n",
      "bw:  12.7 , tau:  6.8 , score:  5994.830526976815\n",
      "bw:  13.0 , tau:  7.2 , score:  5994.823641051885\n",
      "bw:  13.1 , tau:  7.3 , score:  5994.821396243698\n",
      "bw:  13.3 , tau:  7.5 , score:  5994.817392647279\n",
      "bw:  13.3 , tau:  7.5 , score:  5994.817392647279\n",
      "time cost: 0:02:23.782\n",
      "Spatiotemporal Weighted Regression (GTWR) Results\n",
      "---------------------------------------------------------------------------\n",
      "Spatial kernel:                                          Fixed gaussian\n",
      "Model tau used:                                                       7.500\n",
      "Spatial Bandwidth used:                                              13.300\n",
      "Temporal Bandwidth used:                                              4.856\n",
      "\n",
      "Diagnostic information\n",
      "---------------------------------------------------------------------------\n",
      "Residual sum of squares:                                           1922.195\n",
      "Effective number of parameters (trace(S)):                           36.256\n",
      "Degree of freedom (n - trace(S)):                                  2147.744\n",
      "Sigma estimate:                                                       0.946\n",
      "Log-likelihood:                                                   -2959.524\n",
      "AIC:                                                               5993.559\n",
      "AICc:                                                              5994.817\n",
      "BIC:                                                               6034.381\n",
      "R2:                                                                   0.120\n",
      "Adj. alpha (95%):                                                     0.019\n",
      "Adj. critical t value (95%):                                          2.341\n",
      "\n",
      "Summary Statistics For GTWR Parameter Estimates\n",
      "---------------------------------------------------------------------------\n",
      "Variable                   Mean        STD        Min     Median        Max\n",
      "-------------------- ---------- ---------- ---------- ---------- ----------\n",
      "X0                        0.023      0.033     -0.040      0.032      0.064\n",
      "X1                        0.241      0.057      0.160      0.230      0.325\n",
      "X2                        0.021      0.023     -0.017      0.027      0.053\n",
      "X3                        0.015      0.033     -0.019     -0.001      0.088\n",
      "X4                        0.130      0.068      0.013      0.147      0.218\n",
      "X5                        0.091      0.034      0.020      0.096      0.134\n",
      "X6                       -0.133      0.052     -0.202     -0.141     -0.035\n",
      "X7                       -0.038      0.027     -0.077     -0.040      0.025\n",
      "X8                       -0.058      0.041     -0.121     -0.058      0.010\n",
      "X9                        0.026      0.021     -0.008      0.024      0.062\n",
      "X10                       0.039      0.035      0.000      0.025      0.103\n",
      "X11                       0.041      0.029     -0.005      0.046      0.081\n",
      "X12                      -0.033      0.029     -0.073     -0.037      0.014\n",
      "X13                       0.023      0.017     -0.010      0.021      0.056\n",
      "===========================================================================\n",
      "\n",
      "   LONCOL  LATCOL  ts         y        x1        x2        x3        x4        x5        x6       x7      x8        x9       x10      x11       x12       x13      x14      x15       x16       x17       x18                                                                                                        geometry  const_betas  x1_betas  x4_betas  x5_betas  x7_betas  x8_betas  x10_betas  x12_betas  x13_betas  x14_betas  x15_betas  x16_betas  x17_betas  x18_betas\n",
      "0       0       0   0 -0.394639 -1.085337 -1.650384 -1.729306 -1.272613 -1.713273 -1.324008 -1.43865 -1.2494 -1.310982 -1.711913 -1.33971 -1.546237 -1.089479 -1.52412  1.63711 -1.401373  1.501314 -1.991453  POLYGON ((120.22035 30.13370, 120.22035 30.14269, 120.23076 30.14269, 120.23076 30.13370, 120.22035 30.13370))    -0.028196  0.323518 -0.017321  0.000952  0.013916  0.021092  -0.035035  -0.021411   0.008735  -0.001706   0.000774  -0.004761  -0.027774   0.011198\n",
      "1       0       0   1 -0.394639 -1.085337 -1.650384 -1.729306 -1.272613 -1.713273 -1.324008 -1.43865 -1.2494 -1.310982 -1.711913 -1.33971 -1.546237 -1.089479 -1.52412  1.63711 -1.401373  1.501314 -1.991453  POLYGON ((120.22035 30.13370, 120.22035 30.14269, 120.23076 30.14269, 120.23076 30.13370, 120.22035 30.13370))    -0.023267  0.324084 -0.016904 -0.000792  0.017866  0.026819  -0.039408  -0.024988   0.007506  -0.001021   0.001200  -0.003461  -0.032203   0.012381\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "../GTWR_ana\\regre_gtwr.py:173: UserWarning: Column names longer than 10 characters will be truncated when saved to ESRI Shapefile.\n",
      "  df.to_file(result_data_save_file)\n"
     ]
    }
   ],
   "source": [
    "## KSI\n",
    "regre_gtwr.regression.gtwr_start(data_file=\"../../data/merge_data/inj_data_norm/inj_merge_data.shp\",\n",
    "                          explain_var_list=['x1','x4','x5','x7','x8','x10','x12','x13','x14','x15','x16','x17','x18'],\n",
    "                          result_data_save_file=\"../../data/GTWR_result/inj_betas/betas.shp\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4d4ab22d",
   "metadata": {},
   "source": [
    "## 2.3 GWR"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "0070b5d8",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bw: 15.0 , score: 5130.26\n",
      "bw: 10.0 , score: 5119.11\n",
      "bw: 6.0 , score: 5081.5\n",
      "bw: 4.0 , score: 5005.52\n",
      "bw: 2.0 , score: 4753.84\n",
      "bw: 2.0 , score: 4753.84\n",
      "time cost: 0:00:8.487\n",
      "Geographically weighted regression (GWR) Results\n",
      "---------------------------------------------------------------------------\n",
      "Spatial kernel:                                          Fixed gaussian\n",
      "Temporal Bandwidth used:                                              2.000\n",
      "\n",
      "Diagnostic information\n",
      "---------------------------------------------------------------------------\n",
      "Residual sum of squares:                                           1071.791\n",
      "Effective number of parameters (trace(S)):                           52.932\n",
      "Degree of freedom (n - trace(S)):                                  2131.068\n",
      "Sigma estimate:                                                       0.709\n",
      "Log-likelihood:                                                   -2321.647\n",
      "AIC:                                                               4751.157\n",
      "AICc:                                                              4753.837\n",
      "BIC:                                                               4758.627\n",
      "R2:                                                                   0.509\n",
      "Adj. alpha (95%):                                                     0.013\n",
      "Adj. critical t value (95%):                                          2.480\n",
      "\n",
      "Summary Statistics For GWR Parameter Estimates\n",
      "---------------------------------------------------------------------------\n",
      "Variable                   Mean        STD        Min     Median        Max\n",
      "-------------------- ---------- ---------- ---------- ---------- ----------\n",
      "X0                       -0.004      0.141     -0.226     -0.010      0.258\n",
      "X1                        0.570      0.082      0.384      0.528      0.748\n",
      "X2                        0.045      0.042     -0.054      0.050      0.142\n",
      "X3                        0.061      0.117     -0.164      0.017      0.342\n",
      "X4                        0.014      0.099     -0.256      0.023      0.220\n",
      "X5                        0.183      0.067      0.090      0.170      0.330\n",
      "X6                       -0.011      0.055     -0.102     -0.014      0.132\n",
      "X7                       -0.159      0.144     -0.473     -0.146      0.239\n",
      "X8                       -0.076      0.052     -0.226     -0.063      0.028\n",
      "X9                        0.099      0.121     -0.135      0.111      0.382\n",
      "X10                       0.133      0.072     -0.057      0.144      0.266\n",
      "X11                       0.007      0.101     -0.179      0.011      0.232\n",
      "X12                      -0.145      0.108     -0.357     -0.163      0.104\n",
      "X13                       0.154      0.157     -0.156      0.140      0.614\n",
      "===========================================================================\n",
      "\n"
     ]
    }
   ],
   "source": [
    "## PDO\n",
    "regre_gtwr.regression.gwr_start(data_file=\"../../data/merge_data/pdo_data_norm/pdo_merge_data.shp\",\n",
    "                         explain_var_list=['x1','x4','x5','x7','x8','x10','x12','x13','x14','x15','x16','x17','x18'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "c02369b0",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bw: 15.0 , score: 6007.8\n",
      "bw: 10.0 , score: 6006.88\n",
      "bw: 6.0 , score: 6004.18\n",
      "bw: 4.0 , score: 5999.43\n",
      "bw: 2.0 , score: 5985.73\n",
      "bw: 2.0 , score: 5985.73\n",
      "time cost: 0:00:8.59\n",
      "Geographically weighted regression (GWR) Results\n",
      "---------------------------------------------------------------------------\n",
      "Spatial kernel:                                          Fixed gaussian\n",
      "Temporal Bandwidth used:                                              2.000\n",
      "\n",
      "Diagnostic information\n",
      "---------------------------------------------------------------------------\n",
      "Residual sum of squares:                                           1884.300\n",
      "Effective number of parameters (trace(S)):                           52.751\n",
      "Degree of freedom (n - trace(S)):                                  2131.249\n",
      "Sigma estimate:                                                       0.940\n",
      "Log-likelihood:                                                   -2937.781\n",
      "AIC:                                                               5983.064\n",
      "AICc:                                                              5985.726\n",
      "BIC:                                                               5990.895\n",
      "R2:                                                                   0.137\n",
      "Adj. alpha (95%):                                                     0.013\n",
      "Adj. critical t value (95%):                                          2.478\n",
      "\n",
      "Summary Statistics For GWR Parameter Estimates\n",
      "---------------------------------------------------------------------------\n",
      "Variable                   Mean        STD        Min     Median        Max\n",
      "-------------------- ---------- ---------- ---------- ---------- ----------\n",
      "X0                       -0.012      0.069     -0.129     -0.019      0.117\n",
      "X1                        0.289      0.065      0.188      0.289      0.407\n",
      "X2                        0.007      0.040     -0.068      0.016      0.079\n",
      "X3                        0.012      0.033     -0.043      0.006      0.103\n",
      "X4                        0.075      0.070     -0.070      0.066      0.230\n",
      "X5                        0.112      0.034      0.023      0.119      0.167\n",
      "X6                       -0.124      0.070     -0.236     -0.132      0.043\n",
      "X7                       -0.003      0.124     -0.145     -0.056      0.348\n",
      "X8                       -0.009      0.050     -0.091     -0.005      0.130\n",
      "X9                        0.010      0.066     -0.111      0.015      0.131\n",
      "X10                       0.057      0.054     -0.038      0.046      0.252\n",
      "X11                       0.051      0.073     -0.105      0.049      0.219\n",
      "X12                      -0.010      0.084     -0.155     -0.023      0.242\n",
      "X13                      -0.005      0.087     -0.251      0.016      0.120\n",
      "===========================================================================\n",
      "\n"
     ]
    }
   ],
   "source": [
    "## KSI\n",
    "regre_gtwr.regression.gwr_start(data_file=\"../../data/merge_data/inj_data_norm/inj_merge_data.shp\",\n",
    "                         explain_var_list=['x1','x4','x5','x7','x8','x10','x12','x13','x14','x15','x16','x17','x18'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0b265b7f",
   "metadata": {},
   "source": [
    "## 2.4 OLS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "30db977a",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                            OLS Regression Results                            \n",
      "==============================================================================\n",
      "Dep. Variable:                      y   R-squared:                       0.393\n",
      "Model:                            OLS   Adj. R-squared:                  0.389\n",
      "Method:                 Least Squares   F-statistic:                     107.9\n",
      "Date:                Fri, 17 Feb 2023   Prob (F-statistic):          1.07e-223\n",
      "Time:                        16:42:16   Log-Likelihood:                -2554.4\n",
      "No. Observations:                2184   AIC:                             5137.\n",
      "Df Residuals:                    2170   BIC:                             5216.\n",
      "Df Model:                          13                                         \n",
      "Covariance Type:            nonrobust                                         \n",
      "==============================================================================\n",
      "                 coef    std err          t      P>|t|      [0.025      0.975]\n",
      "------------------------------------------------------------------------------\n",
      "const       2.776e-17      0.017   1.66e-15      1.000      -0.033       0.033\n",
      "x1             0.5209      0.018     29.423      0.000       0.486       0.556\n",
      "x2             0.0472      0.018      2.595      0.010       0.012       0.083\n",
      "x3             0.0198      0.018      1.118      0.264      -0.015       0.055\n",
      "x4             0.1135      0.025      4.484      0.000       0.064       0.163\n",
      "x5             0.1497      0.019      7.964      0.000       0.113       0.187\n",
      "x6            -0.0518      0.025     -2.055      0.040      -0.101      -0.002\n",
      "x7            -0.1375      0.028     -4.904      0.000      -0.192      -0.082\n",
      "x8            -0.1266      0.023     -5.514      0.000      -0.172      -0.082\n",
      "x9             0.1153      0.022      5.243      0.000       0.072       0.158\n",
      "x10            0.1043      0.021      4.861      0.000       0.062       0.146\n",
      "x11            0.0229      0.023      1.009      0.313      -0.022       0.068\n",
      "x12           -0.1424      0.024     -5.883      0.000      -0.190      -0.095\n",
      "x13            0.1685      0.034      4.885      0.000       0.101       0.236\n",
      "==============================================================================\n",
      "Omnibus:                      875.129   Durbin-Watson:                   1.073\n",
      "Prob(Omnibus):                  0.000   Jarque-Bera (JB):             5207.316\n",
      "Skew:                           1.788   Prob(JB):                         0.00\n",
      "Kurtosis:                       9.666   Cond. No.                         4.60\n",
      "==============================================================================\n",
      "\n",
      "Notes:\n",
      "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n"
     ]
    }
   ],
   "source": [
    "## PDO\n",
    "regre_gtwr.regression.ols_start(data_file=\"../../data/merge_data/pdo_data_norm/pdo_merge_data.shp\",\n",
    "                         explain_var_list=['x1','x4','x5','x7','x8','x10','x12','x13','x14','x15','x16','x17','x18'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "e638808f",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                            OLS Regression Results                            \n",
      "==============================================================================\n",
      "Dep. Variable:                      y   R-squared:                       0.096\n",
      "Model:                            OLS   Adj. R-squared:                  0.090\n",
      "Method:                 Least Squares   F-statistic:                     17.65\n",
      "Date:                Fri, 17 Feb 2023   Prob (F-statistic):           1.95e-39\n",
      "Time:                        16:42:16   Log-Likelihood:                -2989.2\n",
      "No. Observations:                2184   AIC:                             6006.\n",
      "Df Residuals:                    2170   BIC:                             6086.\n",
      "Df Model:                          13                                         \n",
      "Covariance Type:            nonrobust                                         \n",
      "==============================================================================\n",
      "                 coef    std err          t      P>|t|      [0.025      0.975]\n",
      "------------------------------------------------------------------------------\n",
      "const       4.734e-16      0.020   2.32e-14      1.000      -0.040       0.040\n",
      "x1             0.2681      0.022     11.947      0.000       0.224       0.312\n",
      "x2             0.0149      0.022      0.671      0.502      -0.029       0.059\n",
      "x3             0.0215      0.022      0.992      0.321      -0.021       0.064\n",
      "x4             0.1093      0.031      3.517      0.000       0.048       0.170\n",
      "x5             0.0891      0.023      3.882      0.000       0.044       0.134\n",
      "x6            -0.1229      0.031     -3.997      0.000      -0.183      -0.063\n",
      "x7            -0.0328      0.034     -0.958      0.338      -0.100       0.034\n",
      "x8            -0.0478      0.028     -1.702      0.089      -0.103       0.007\n",
      "x9             0.0166      0.027      0.612      0.541      -0.037       0.070\n",
      "x10            0.0372      0.026      1.423      0.155      -0.014       0.088\n",
      "x11            0.0327      0.028      1.184      0.237      -0.021       0.087\n",
      "x12           -0.0314      0.029     -1.066      0.287      -0.089       0.026\n",
      "x13            0.0125      0.042      0.294      0.769      -0.071       0.096\n",
      "==============================================================================\n",
      "Omnibus:                     1379.179   Durbin-Watson:                   1.905\n",
      "Prob(Omnibus):                  0.000   Jarque-Bera (JB):            14985.713\n",
      "Skew:                           2.882   Prob(JB):                         0.00\n",
      "Kurtosis:                      14.465   Cond. No.                         4.61\n",
      "==============================================================================\n",
      "\n",
      "Notes:\n",
      "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n"
     ]
    }
   ],
   "source": [
    "## KSI\n",
    "regre_gtwr.regression.ols_start(data_file=\"../../data/merge_data/inj_data_norm/inj_merge_data.shp\",\n",
    "                         explain_var_list=['x1','x4','x5','x7','x8','x10','x12','x13','x14','x15','x16','x17','x18'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b0affdaf",
   "metadata": {},
   "source": [
    "## 3.1 Analysis of the Characteristics of Time Dimension"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "757e18f4",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正在可视化x1_betas\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'data_st_vis' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-1-33935f5cc311>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      5\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"正在可视化{0}\"\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtmp_col\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      6\u001b[0m     \u001b[0mtmp_save_file\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"../../data/GTWR_result/pdo_result/\"\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mtmp_col\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m\"_vis.csv\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m     data_st_vis.vis.temporal_vis(beta_file=\"../../data/GTWR_result/pdo_betas/betas.shp\",\n\u001b[0m\u001b[0;32m      8\u001b[0m                          \u001b[0mcolumn_name\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtmp_col\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      9\u001b[0m                          data_save_file=tmp_save_file)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'data_st_vis' is not defined"
     ]
    }
   ],
   "source": [
    "## PDO\n",
    "explain_var_list=['x1','x4','x5','x7','x8','x10','x12','x13','x14','x15','x16','x17','x18']\n",
    "for i in range(len(explain_var_list)):\n",
    "    tmp_col = explain_var_list[i]+\"_betas\"\n",
    "    print(\"正在可视化{0}\".format(tmp_col))\n",
    "    tmp_save_file = \"../../data/GTWR_result/pdo_result/\" + tmp_col + \"_vis.csv\"\n",
    "    data_st_vis.vis.temporal_vis(beta_file=\"../../data/GTWR_result/pdo_betas/betas.shp\",\n",
    "                         column_name=tmp_col,\n",
    "                         data_save_file=tmp_save_file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "99f50bdd",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正在可视化x1_betas\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'data_st_vis' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-2-033ad6af1753>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      5\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"正在可视化{0}\"\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtmp_col\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      6\u001b[0m     \u001b[0mtmp_save_file\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"../../data/GTWR_result/inj_result/\"\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mtmp_col\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m\"_vis.csv\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m     data_st_vis.vis.temporal_vis(beta_file=\"../../data/GTWR_result/inj_betas/betas.shp\",\n\u001b[0m\u001b[0;32m      8\u001b[0m                          \u001b[0mcolumn_name\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtmp_col\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      9\u001b[0m                          data_save_file=tmp_save_file)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'data_st_vis' is not defined"
     ]
    }
   ],
   "source": [
    "## KSI\n",
    "explain_var_list=['x1','x4','x5','x7','x8','x10','x12','x13','x14','x15','x16','x17','x18']\n",
    "for i in range(len(explain_var_list)):\n",
    "    tmp_col = explain_var_list[i]+\"_betas\"\n",
    "    print(\"正在可视化{0}\".format(tmp_col))\n",
    "    tmp_save_file = \"../../data/GTWR_result/inj_result/\" + tmp_col + \"_vis.csv\"\n",
    "    data_st_vis.vis.temporal_vis(beta_file=\"../../data/GTWR_result/inj_betas/betas.shp\",\n",
    "                         column_name=tmp_col,\n",
    "                         data_save_file=tmp_save_file)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "60bca28d",
   "metadata": {},
   "source": [
    "## 3.2 Analysis of the Characteristics of Spatial Dimensions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0e621c9f",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正在可视化x1_betas\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'os' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-3-aa5296f246f3>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      5\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"正在可视化{0}\"\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtmp_col\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      6\u001b[0m     \u001b[0mtmp_save_path\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"../../data/GTWR_result/pdo_result/\"\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mtmp_col\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m\"_vis/\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m     \u001b[0mos\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmkdir\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtmp_save_path\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      8\u001b[0m     data_st_vis.vis.spatial_vis(beta_file=\"../../data/GTWR_result/pdo_betas/betas.shp\",\n\u001b[0;32m      9\u001b[0m                     \u001b[0mcolumn_name\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtmp_col\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'os' is not defined"
     ]
    }
   ],
   "source": [
    "## PDO\n",
    "explain_var_list=['x1','x4','x5','x7','x8','x10','x12','x13','x14','x15','x16','x17','x18']\n",
    "for i in range(len(explain_var_list)):\n",
    "    tmp_col = explain_var_list[i]+\"_betas\"\n",
    "    print(\"正在可视化{0}\".format(tmp_col))\n",
    "    tmp_save_path = \"../../data/GTWR_result/pdo_result/\" + tmp_col + \"_vis/\"\n",
    "    os.mkdir(tmp_save_path)\n",
    "    data_st_vis.vis.spatial_vis(beta_file=\"../../data/GTWR_result/pdo_betas/betas.shp\",\n",
    "                    column_name=tmp_col,\n",
    "                    dev_file=\"../../data/distinct_camera.xlsx\",\n",
    "                    data_save_file=tmp_save_path + tmp_col + \"_vis.shp\",\n",
    "                    image_save_path=\"../../data/GTWR_result/tile_file/\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "fa01f2a4",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正在可视化x1_betas\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'os' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-4-d032ceb78266>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      5\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"正在可视化{0}\"\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtmp_col\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      6\u001b[0m     \u001b[0mtmp_save_path\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"../../data/GTWR_result/inj_result/\"\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mtmp_col\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m\"_vis/\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m     \u001b[0mos\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmkdir\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtmp_save_path\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      8\u001b[0m     data_st_vis.vis.spatial_vis(beta_file=\"../../data/GTWR_result/inj_betas/betas.shp\",\n\u001b[0;32m      9\u001b[0m                     \u001b[0mcolumn_name\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtmp_col\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'os' is not defined"
     ]
    }
   ],
   "source": [
    "## KSI\n",
    "explain_var_list=['x1','x4','x5','x7','x8','x10','x12','x13','x14','x15','x16','x17','x18']\n",
    "for i in range(len(explain_var_list)):\n",
    "    tmp_col = explain_var_list[i]+\"_betas\"\n",
    "    print(\"正在可视化{0}\".format(tmp_col))\n",
    "    tmp_save_path = \"../../data/GTWR_result/inj_result/\" + tmp_col + \"_vis/\"\n",
    "    os.mkdir(tmp_save_path)\n",
    "    data_st_vis.vis.spatial_vis(beta_file=\"../../data/GTWR_result/inj_betas/betas.shp\",\n",
    "                    column_name=tmp_col,\n",
    "                    dev_file=\"../../data/distinct_camera.xlsx\",\n",
    "                    data_save_file=tmp_save_path + tmp_col + \"_vis.shp\",\n",
    "                    image_save_path=\"../../data/GTWR_result/tile_file/\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b99500bf",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
